-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTypingUsersTests.swift
127 lines (100 loc) · 3.72 KB
/
TypingUsersTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Wire
// Copyright (C) 2024 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
@testable import WireSyncEngine
class TypingUsersTests: MessagingTest {
private typealias TypingUsers = WireSyncEngine.TypingUsers
private var sut: TypingUsers!
private var user1: ZMUser!
private var user2: ZMUser!
private var selfUser: ZMUser!
private var conversation1: ZMConversation!
private var conversation2: ZMConversation!
override func setUp() {
super.setUp()
sut = TypingUsers()
user1 = ZMUser.insertNewObject(in: uiMOC)
user1.name = "Hans"
user2 = ZMUser.insertNewObject(in: uiMOC)
user2.name = "Gretel"
selfUser = ZMUser.insertNewObject(in: uiMOC)
selfUser.name = "Myself"
conversation1 = ZMConversation.insertNewObject(in: uiMOC)
conversation1.userDefinedName = "A Walk in the Forest"
conversation2 = ZMConversation.insertNewObject(in: uiMOC)
conversation2.userDefinedName = "The Great Escape"
XCTAssert(uiMOC.saveOrRollback())
}
override func tearDown() {
sut = nil
user1 = nil
user2 = nil
selfUser = nil
conversation1 = nil
conversation2 = nil
super.tearDown()
}
// MARK: - Tests
func testThatItReturnsAnEmptySetByDefault() {
// Given, then
XCTAssertEqual(sut.typingUsers(in: conversation1), Set())
}
func testThatItReturnsTheTypingUsers() {
// Given
let users: Set<ZMUser> = Set([user1, user2])
// When
sut.update(typingUsers: users, in: conversation1)
// Then
XCTAssertEqual(sut.typingUsers(in: conversation1), users)
XCTAssertEqual(sut.typingUsers(in: conversation2), Set())
}
func testThatItUpdatesTheTypingUsers() {
// Given
let usersA: Set<ZMUser> = Set([user1, user2])
let usersB: Set<ZMUser> = Set([user1])
// When
sut.update(typingUsers: usersA, in: conversation1)
sut.update(typingUsers: usersB, in: conversation1)
// Then
XCTAssertEqual(sut.typingUsers(in: conversation1), usersB)
XCTAssertEqual(sut.typingUsers(in: conversation2), Set())
}
func testThatItUpdatesMultipleConversations() {
// Given
let usersA: Set<ZMUser> = Set([user1])
let usersB: Set<ZMUser> = Set([user1])
// When
sut.update(typingUsers: usersA, in: conversation1)
sut.update(typingUsers: usersB, in: conversation2)
// Then
XCTAssertEqual(sut.typingUsers(in: conversation1), usersA)
XCTAssertEqual(sut.typingUsers(in: conversation2), usersB)
}
func testThatItAddsAnInstanceToTheUiContext() {
// When
sut = uiMOC.typingUsers
// Then
XCTAssertNotNil(sut)
XCTAssertTrue(sut.isKind(of: TypingUsers.self))
XCTAssertEqual(sut, uiMOC.typingUsers)
}
func testThatItDoesNotAddAnInstanceToTheSyncContext() {
// When, then
syncMOC.performGroupedBlockAndWait { XCTAssertNil(self.syncMOC.typingUsers) }
XCTAssert(waitForAllGroupsToBeEmpty(withTimeout: 0.5))
}
}